package com.nd.controller;


import com.baomidou.mybatisplus.generator.config.ITypeConvert;
import com.nd.common.result.ResultUtils;
import com.nd.entity.Type;
import com.nd.entity.Users;
import com.nd.service.IOrdersService;
import com.nd.service.ITypeService;
import com.nd.service.IUsersService;
import com.nd.service.impl.UsersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.security.krb5.internal.crypto.EType;

import javax.websocket.server.PathParam;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 *  用户的接口测试
 * @author liruirui
 * @since 2024-12-25
 */
@RestController
@RequestMapping("/type")
public class TypeController {

    @Autowired
    ITypeService service;

    /**
     * 全查
     * @return
     */
    @GetMapping("/")
    public Object getList(){
        return ResultUtils.returnSuccessLayui(service.list(),service.list().size());
    }

    /**
     * 根据id查询单个
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Object getById(@PathVariable("id")Integer id){
        return service.getById(id);
    }

    /**
     * 根据id删除单个
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Object del(@PathVariable("id")Integer id){
        if(service.removeById(id)){
            return ResultUtils.returnSuccess();
        }else{
            return ResultUtils.returnFail("删除失败");
        }
    }


    /**
     * 添加
     * @param
     * @return
     */
    @PostMapping("/")
    public Object add(@RequestBody Type type){
        if(service.save(type)){
            return ResultUtils.returnSuccess();
        }else{
            return ResultUtils.returnFail("添加失败");
        }
    }



    /**
     * 修改
     * @param
     * @return
     */
    @PutMapping("/")
    public Object update(@RequestBody Type type){
        if(service.updateById(type)){
            return ResultUtils.returnSuccess();
        }else{
            return ResultUtils.returnFail("修改失败");
        }
    }



}
